﻿using System;
using System.ServiceModel;

using BLToolkit.Reflection;

using EMan.Common;
using EMan.Common.EnterpriseStructure;
using EMan.Server.BL;

using TrueCode.Core.Aspects;

namespace EMan.Server.WCF
{
//  [ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple
//#if DEBUG
//    , IncludeExceptionDetailInFaults = true
//#endif
//    )]
//  public class EManServicePlain : IEMan, IEnterpriseStructure
//  {
//    public EManServicePlain()
//    {
//      Console.WriteLine( ".ctor" );
//    }
//
//    public IList< Department > GetAllDepartments()
//    {
//      throw new NotImplementedException();
//    }
//
//    public StructureChangeset UpdateStructure( StructureChangeset changeset )
//    {
//      Console.WriteLine( "Updata" );
//     return changeset;
//    }
//  }

 [ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple
#if DEBUG
    , IncludeExceptionDetailInFaults = true
#endif
    )]
  [BLToolkit.Aspects.Mixin( typeof(IEMan), "Server", true )]
  [BLToolkit.Aspects.Mixin( typeof(IEnterpriseStructure), "Server", true )]
  public abstract class EManService
  {
    private EManImpl _server;

    [NotNull]
    public EManImpl Server
    {
      get
      {
        Console.WriteLine( "GetServer " + _server );
        return _server;
      }
      private set
      {
        if( value == null ) throw new ArgumentNullException( "value" );
        _server = value;
      }
    }

   [UsedImplicitly]
   public static EManService Create( EManImpl server )
   {
     var emanService = TypeAccessor< EManService >.CreateInstance();
     emanService.Server = server;
     return emanService;
   }
  }
}
